<template>
  <div class="follower-page-container">
    <h2 class="page-title">我的粉丝</h2>
    <ul class="user-list">
      <li
        v-for="follower in followers"
        :key="follower.id"
        @click="goToFollowerPersonalPage(follower.id)"
        style="cursor: pointer;"
      >
        <img
          :src="
            follower.avatar
              ? `data:image/jpeg;base64,${follower.avatar}`
              : 'https://picsum.photos/100/100?random=4'
          "
          alt="用户头像"
          class="user-avatar"
        />
        <div class="user-info">
          <h3 class="user-name">{{ follower.nickname }}</h3>
          <p class="user-intro">{{ follower.personalIntroduction }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  components: {},
  name: "FollowerPage",
  data() {
    return {
      followers: [],
    };
  },
  mounted() {
    this.fetchFollowers();
  },
  methods: {
    async fetchFollowers() {
      const userId = this.$route.params.userId;
      try {
        const response = await this.$axios.get(`/follower/list/${userId}`);
        if (response.data.code === 200) {
          const followerIds = response.data.data.map((follower) => follower.followerUserId);
          const followerPromises = followerIds.map(async (id) => {
            const userResponse = await this.$axios.get(`/user/info/${id}`);
            if (userResponse.data.code === 200) {
              const user = userResponse.data.data;
              const userInfoResponse = await this.$axios.get(`/userInfo/get/${id}`);
              if (userInfoResponse.data.code === 200) {
                user.personalIntroduction = userInfoResponse.data.data.personalIntroduction;
              }
              return user;
            }
            return null;
          });
          const allFollowers = await Promise.all(followerPromises);
          this.followers = allFollowers.filter((follower) => follower !== null);
        }
      } catch (error) {
        console.error("获取粉丝列表失败", error);
      }
    },
    goToFollowerPersonalPage(followerId) {
      this.$router.push(`/user/${followerId}`);
    },
  },
};
</script>

<style scoped>
.follower-page-container {
  padding: 30px 40px;
  min-height: 100vh;
  background: transparent;
  position: relative;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.page-title {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 30px;
  position: relative;
  padding-left: 15px;
}

.page-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  height: 20px;
  width: 5px;
  background: #ffb76b;
  border-radius: 3px;
}

.user-list {
  list-style: none;
  padding: 0;
}

.user-list li {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(5px);
  border-radius: 20px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 20px;
  transition: transform 0.3s;
}

.user-list li:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.12);
}

.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border: 3px solid white;
}

.user-info {
  flex: 1;
}

.user-name {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 5px;
}

.user-intro {
  font-size: 14px;
  color: #606266;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>